We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get params from url using <a href='' ''>

Hi everyone, I try to dump value comes from url to see what happen , but I've got null value any idea ?

public function historiqueEmpAction(){          
            $conge = array();
            $i = 0;
            $entite = Entite::findFirst("id_sup='".$this->session->get('IdUser')."'");
            $persons = Personnel::find(array(
                                        "id_entite='".$entite->getId()."'",
                                         "order" => "nom"));

                foreach ($persons as $person){

                    if(strcmp($person->getId(),$this->session->get("IdSup")!==0)){
                        $dbconges = Conge::find(array(
                                                "id_personnel='".$person->getId()."'",
                                                "order" => "date DESC"));

                        foreach($dbconges as $conges){
                                                        $conge[$i]['idEm'] = $person->getId();
                                                        $conge[$i]['nom'] = $person->getNom();
                                                        $conge[$i]['prenom'] = $person->getPrenom();
                                                        $conge[$i]['date'] = $conges->getDate();
                                                        $conge[$i]['nbrjour'] = $conges->getNbr_jour();
                                                        $i++;

                    }
                 }
              }

              $this->view->conges = $conge;            
    }

    public function listeCongeEmpAction(){

        $this->view->disable();
       $x = $this->dispatcher->getParam('idEmp');
       var_dump($x);   
    }

and my view :

    {% block content %}
<th>Date de la demande</th><th>Nom Complet</th><th>Nombre des jours</th>
                {% for valeur in conges %}
    <tr>
          <td align='center'>{{ valeur['date'] }}</td>
          <td align='center'><a href="{{ url('administration/conge/listeCongeEmp/idEmp/')}}{{valeur['idEm']}}">                                                 {{              valeur['nom'] }} {{ valeur['prenom'] }}</a></td>
          <td align='center'>{{ valeur['nbrjour'] }}</td>
     </tr>
  {% endfor %}


43.9k

Hi,

in your view:

{{ url('administration/conge/listeCongeEmp/idEmp/'~valeur['idEm'] }}



5.7k
Accepted
answer
edited May '15

If you don't name the parameter in your router, you can't call by name if I remember correctly, only via. $this->dispatcher->getParams()

Yeah, it returns: [idEmp, value1, key2, value2]

You can use something like this:


    $params = $this->dispatcher->getParams();
    $counted = count($params);
    $paired = [];
    for ( $i = 0; $i < $counted; $i = $i + 2) {
        if (!empty($params[$i + 1])) {
            $paired[$params[$i]] = $params[$i + 1];
        } else {
            $paired[$i] = $params[$i];
        }
    }

So then echo $paired['idEmp'] is 'value1'.



5.8k

Thank you Edward